

package model.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import model.entities.CallsRole;
import model.entities.Role;
import model.entities.RoleSV;

/**
 *
 * @author Hieu.Nguyen
 */
public class CallsRoleDAO {
    private static CallsRoleDAO callsRoleDAO;

    public static CallsRoleDAO getInstance() {
        if (callsRoleDAO == null) {
            callsRoleDAO  = new CallsRoleDAO();
        }
        return callsRoleDAO ;
    }
    
     public List<CallsRole> getCallsRole(boolean isActived) {
        List<CallsRole> listCallsRole = new ArrayList<CallsRole>();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblCallsRole";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                model.entities.CallsRole r = new model.entities.CallsRole();
                r.setCallsRoleID(rs.getInt("CallsRoleID"));
                r.setCallsRoleName(rs.getString("CallsRoleName"));
                r.setCallsRoleNameDescrp(rs.getString("CallsRoleDescription"));
                listCallsRole.add(r);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listCallsRole;
    }
      public CallsRole getCallsRoleByID(int calRole) {

        CallsRole cl = new CallsRole();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblCallsRole where CallsRoleID = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, calRole);
            
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                
                cl.setCallsRoleID(rs.getInt("CallsRoleID"));
                cl.setCallsRoleName(rs.getString("CallsRoleName"));
                cl.setCallsRoleNameDescrp(rs.getString("CallsRoleDescription"));
             
                
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return cl;
     }
     
    
}
